<template>
  <div class="app-container calendar-list-container">
    <!--分帐明细 filter 条件查询 -->
    <div class="filter-container">
      <el-input
        clearable
        @keyup.enter.native="handleFilter"
        v-model="listQuery.nickName"
        style="width: 200px;margin-right:15px;margin-top:7px"
        class="filter-item"
        placeholder="请输入昵称"
      />
      <el-input
        clearable
        @keyup.enter.native="handleFilter"
        v-model="listQuery.userPhone"
        style="width: 200px;margin-right:15px;margin-top:7px"
        class="filter-item"
        placeholder="请输入手机号"
      />
      <el-input
        clearable
        @keyup.enter.native="handleFilter"
        v-model="listQuery.outTradeNo"
        style="width: 300px;margin-right:15px;margin-top:7px"
        class="filter-item"
        placeholder="请输入支付流水号"
      />

      <el-select
        v-model="listQuery.financeType"
        placeholder="请选择财务类型"
        clearable
        class="filter-item"
        style="width: 150px;margin-right:15px;margin-top:7px"
      >
        <!--  1充电支付 2余额充值  3Ic充值 4Ic购买 5.会卡购买 6退款 -->
        <el-option label="充电支付" value="1"></el-option>
        <el-option label="余额充值" value="2"></el-option>
        <el-option label="Ic卡充值" value="3"></el-option>
        <!-- <el-option label="Ic卡购买" value="4"></el-option> -->
        <el-option label="月卡购买" value="4"></el-option>
        <el-option label="退款" value="5"></el-option>
      </el-select>
      <el-select
        v-model="listQuery.payType"
        placeholder="请选择交易类型"
        clearable
        class="filter-item"
        style="width: 200px;margin-right:15px;margin-top:7px"
      >
        <el-option label="微信" value="1"></el-option>
        <!-- <el-option label="支付宝" value="2"></el-option> -->
        <el-option label="余额" value="3"></el-option>
        <el-option label="ic卡" value="5"></el-option>
      </el-select>

            <!-- 2022.09.07  合并为时间日期选择器 -->
      <el-date-picker
        v-model="dateTime"
        type="datetimerange"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        value-format="yyyy-MM-dd HH:mm:00"
        @change="getDateTime"
      >
      </el-date-picker>
      <!-- <el-date-picker
        v-model="listQuery.startTime"
        type="datetime"
        value-format="yyyy-MM-dd HH:mm:ss"
        style="width: 200px;margin-right:15px;margin-top:7px"
        placeholder="选择开始日期"
      ></el-date-picker>
      <el-date-picker
        v-model="listQuery.endTime"
        type="datetime"
        style="width: 200px;margin-right:15px;margin-top:7px"
        value-format="yyyy-MM-dd HH:mm:ss"
        placeholder="选择结束日期"
      ></el-date-picker> -->

      <br />
      <br />
      <el-button
        class="filter-item"
        type="primary"
        v-waves
        icon="el-icon-search"
        @click="handleFilter"
      >查找</el-button>
      <el-button
        type="primary"
        class="filter-item"
        @click="handleDownload"
        icon="el-icon-download"
        :loading="downloadLoading"
      >导出</el-button>
    </div>
    <!-- table 表格 -->
    <el-table
      :data="list"
      v-loading="loading.list"
      element-loading-text="给我一点时间"
      border
      fit
      highlight-current-row
      style="width: 100%"
      max-height="830"
    >
      <el-table-column label="序号" prop="index" align="center" />
      <el-table-column label="昵称" prop="nickName" align="center" />
      <el-table-column label="手机号" prop="userPhone" align="center" />
      <el-table-column label="ic卡号" prop="cardNo" align="center" />
      <el-table-column label="支付流水号" prop="outTradeNo" align="center"  />
      <el-table-column label="总金额(元)" prop="balanceInfo" align="center" />
      <el-table-column label="实际金额(元)" prop="expensesAmountInfo" align="center" />
      <el-table-column label="增送金额(元)" prop="givenAmountInfo" align="center" />
      <el-table-column label="财务类型" prop="financeTypeInfo" align="center" />
      <el-table-column label="交易类型" prop="payTypeInfo" align="center" />
      <el-table-column label="创建时间" prop="ctime" align="center" />
    </el-table>
    <!-- pagination 分页 -->
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="listQuery.offset"
        :page-sizes="[10, 20, 30, 40,100,300,500,5000,10000]"
        :page-size="listQuery.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { getBackUserFinanceList } from "@/api/financial";
import { parseTime, getdTime } from "@/utils";
export default {
  name: "financial_financeUser",
  data() {
    return {
      dateTime:"",
      total: 0,
      listQuery: {
        offset: 1,
        limit: 10,
        outTradeNo: "",
        nickName: "",
        userPhone: "",
        financeType: "",
        payType: "",
        startTime: "",
        endTime: ""
      },
      list: null,
      loading: {
        list: false,
        download: false
      },
      downloadLoading: false
    };
  },
  methods: {
        getDateTime(value) {
      if (value) {
        this.listQuery.startTime = value[0];
        this.listQuery.endTime = value[1];
      } else {
        this.listQuery.startTime = "";
        this.listQuery.endTime = "";
      }
    },
    //导出
    handleDownload() {
      this.downloadLoading = true;
      import("@/vendor/Export2Excel").then(excel => {
        const tHeader = [
            "昵称",
            "手机号",
          "ic卡号",
          "支付流水号",
          "总金额（元）",
          "实际金额（元）",
          "赠送金额（元）",
          "财务类型",
          "交易类型",
          "创建时间",
        ];
        const filterVal = [
          "nickName",
          "userPhone",
          "cardNo",
          "outTradeNo",
          "balanceInfo",
          "expensesAmountInfo",
          "givenAmountInfo",
          "financeTypeInfo",
           "payTypeInfo",
          "ctime",
        ];
        const data = this.formatJson(filterVal, this.list);
        excel.export_json_to_excel({
          header: tHeader,
          data,
          filename: "用户财务"
        });
        this.downloadLoading = false;
      });
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v =>
        filterVal.map(j => {
          return v[j];
        })
      );
    },
    //分帐明细列表

    async getList() {
      this.loading.list = true;
      try {
        //调用服务器接口
        const { data } = await getBackUserFinanceList({ ...this.listQuery });
        this.list = data.records.map((item, index) => {
          return {
            index: index + 1,
            balanceInfo: item.balance / 100,
            cardNo: item.cardNo ? item.cardNo : "-",
            expensesAmountInfo:item.expensesAmount ?  item.expensesAmount / 100:"-",
            givenAmountInfo: item.givenAmount ? item.givenAmount / 100 : "-",
            //  1充电支付 2余额充值  3Ic充值  4.会卡购买 5退款

            financeTypeInfo:
              item.financeType == 1
                ? "充电支付"
                : item.financeType == 2
                ? "余额充值"
                : item.financeType == 3
                ? "Ic卡充值"
                : item.financeType == 4
                ? "月卡购买"
                : item.financeType == 5
                ? "退款"
                : "-",
            payTypeInfo:
              item.payType == 1
                ? "微信"
                : item.payType == 2
                ? "支付宝"
                : item.payType == 3
                ? "余额"
                : item.payType == 4
                ? "月卡"
                : item.payType == 5
                ? "ic卡"
                : "-",
            ...item
          };
        });
        this.total = data.total;
      } catch (error) {}
      this.loading.list = false;
    },
    handleFilter() {
      this.listQuery.offset = 1;
      this.getList();
    },
    handleSizeChange(val) {
      this.listQuery.limit = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.offset = val;
      this.getList();
    },
    formatDate(date, offset) {
      if (date && typeof date == "object") {
        const d = date[offset];
        return new Date(d).getTime();
      }
      return "";
    }
  },
  created() {
     
    this.getList();
  }
};
</script>
